package com.masterclient.app.modules.aftersale;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.masterclient.app.R;
import com.eoner.baselibrary.bean.aftersale.ReturnGoodsBean;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.weigan.loopview.LoopView;
import com.weigan.loopview.OnItemSelectedListener;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：sean
 * 创建时间：2017/8/26 11:49
 * 功能说明：
 */

public class ReturnReasonDialog extends Dialog{

    public ReturnReasonDialog(@NonNull Context context) {
        super(context,R.style.MyDialog);
    }

    public void setList(List<ReturnGoodsBean.DataBean.ShReasonBean> list) {
        strList.clear();
        for(int i = 0;i<list.size();i++){
            strList.add(list.get(i).getSh_reason_name());
        }
        loopView.setItems(strList);
    }

    public void setReceiveList(List<ReturnGoodsBean.DataBean.ShReceiveStatusListBean> list) {
        strList.clear();
        for(int i = 0;i<list.size();i++){
            strList.add(list.get(i).getSh_status_text());
        }
        loopView.setItems(strList);
    }





    private TextView tv_cancle,tv_confirm;
    private LoopView loopView;
    private List<String> strList;

    private int selectedPosition;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_return_reason);

        tv_cancle = (TextView) findViewById(R.id.tv_cancle);
        tv_confirm = (TextView) findViewById(R.id.tv_confirm);
        loopView = (LoopView) findViewById(R.id.loopView);

        strList = new ArrayList<>();
        loopView.setListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                selectedPosition = index;
            }
        });


        tv_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        tv_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onConfirmListener!=null){
                    onConfirmListener.onConfirm(selectedPosition);
                }
                dismiss();
            }
        });

    }

    public void setOnConfirmListener(OnConfirmListener onConfirmListener) {
        this.onConfirmListener = onConfirmListener;
    }

    private OnConfirmListener onConfirmListener;

    public interface OnConfirmListener{
        public void onConfirm(int index);
    }

    @Override
    protected void onStart() {
        super.onStart();
        Window window = getWindow();
        window.setWindowAnimations(R.style.bottomShow);
        WindowManager.LayoutParams windowparams = window.getAttributes();
        window.setGravity(Gravity.BOTTOM);
        windowparams.width = ScreenUtils.getScreenWidth();
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setAttributes(windowparams);
    }
}
